package InputStreamReader_;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * @author feng
 * @Date 2021/12/27 15:45
 * 转换流，可以指定编码格式，处理乱码问题。将字节流转换成字符流。
 */
public class InputStreamReaderTest {
    public static void main(String[] args) throws IOException {
        String path = "D:\\IO\\1.text";
        InputStreamReader reader;
        //转换流
        reader = new InputStreamReader(new FileInputStream(path), "gbk");
        char[] chars = new char[8];
        int c = 0;
        while ((c = reader.read(chars)) != -1) {
            System.out.print(new String(chars, 0, c));
        }
        //BufferedReader reader1 = new BufferedReader(reader);

//        try {
//            String s = reader1.readLine();
//            System.out.println("读取到的内容" + s);
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            reader1.close();
//        }
    }
}
